<?php

namespace App\Domain\HealthHistory\Dao;

use App\Domain\HealthHistory\Models\OperationModel;
use App\Domain\HealthHistory\Models\DiseaseModel;
use App\Domain\HealthHistory\Models\AllergyModel;

class HealthHistoryDao
{
    public function findByDiseaseUid($uid)
    {
        $data = DiseaseModel::where('uid', $uid)->first();
        return $data;
    }

    public function findByDiseaseUidAndWhere($param)
    {
        $data = DiseaseModel::where('uid', $param['memberUid'])->where('where',$param['where'])->first();
        return $data;
    }

    public function findByAllergyUid($uid)
    {
        $data = AllergyModel::where('uid', $uid)->first();
        return $data;
    }

    public function findByOperationUid($uid)
    {
        $data = OperationModel::where('uid', $uid)->first();
        return $data;
    }

    /**
     * 修改过往病史（家庭病史）记录
     * @param DiseaseModel $model
     * @param $param
     * @return DiseaseModel
     */
    public function updateDisease(DiseaseModel $model, $param)
    {
        $param = array_filter_null($param);
        $model->fill($param)->save();
        return $model;
    }

    /**
     * 创建过往病史（家庭病史）记录
     * @param $params
     * @return DiseaseModel
     */
    public function createDisease($params)
    {
        $params = array_filter_null($params);
        return DiseaseModel::create($params);
    }

    /**
     * 修改过敏史记录
     * @param AllergyModel $model
     * @param $param
     * @return AllergyModel
     */
    public function updateAllergy(AllergyModel $model, $param)
    {
        $param = array_filter_null($param);
        $model->fill($param)->save();
        return $model;
    }

    /**
     * 创建过敏史记录
     * @param $params
     * @return AllergyModel
     */
    public function createAllergy($params)
    {
        $params = array_filter_null($params);
        return AllergyModel::create($params);
    }

    /**
     * 修改手术史记录
     * @param OperationModel $model
     * @param $param
     * @return OperationModel
     */
    public function updateOperation(OperationModel $model, $param)
    {
        $param = array_filter_null($param);
        $model->fill($param)->save();
        return $model;
    }

    /**
     * 创建手术史记录
     * @param $params
     * @return OperationModel
     */
    public function createOperation($params)
    {
        $params = array_filter_null($params);
        return OperationModel::create($params);
    }

}
